import { Controller, Get, Query, UseGuards, Post, Body, Req } from '@nestjs/common';
import { AppService } from './app.service';
import { ApiUseTags, ApiOperation } from '@nestjs/swagger';
import { LoginUserDto } from './systems/users/dtos/login-user-dto';
import { AuthGuard } from '@nestjs/passport';
import { Request } from 'express';

@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    ) {

    } 
  @ApiUseTags('用户登录接口API')
  @ApiOperation({title:'用户登录'})
  @Post('login')
  async login(@Body() loginDto: LoginUserDto,@Req() req: Request) {
    let ip;
    try{
      ip= req.headers['x-wq-realip'] ||
          req.connection.remoteAddress ||
          req.socket.remoteAddress ||
          req.connection.remoteAddress;
    }catch(e){
      return "";
    }
    return await this.appService.login(loginDto.userName, loginDto.password,ip);
  }
}
